package com.beyondbit.hr.api.utils;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;

import java.util.List;
import java.util.Map;

public class JsonUtils {
    public static ObjectMapper objectMapper(){
        return new ObjectMapper();
    }

    public static TypeFactory typeFactory(){
        return TypeFactory.defaultInstance();
    }

    public static JavaType javaType(Class<?> clazz){
        return typeFactory().constructType(clazz);
    }

    public static JavaType parametricJavaType(Class<?> parametrized,Class<?> ... parameterClasses){
        return typeFactory().constructParametricType(parametrized,parameterClasses);
    }

    public static JavaType parametricJavaType(Class<?> parametrized,JavaType ... parameterTypes){
        return typeFactory().constructParametricType(parametrized,parameterTypes);
    }

    public static JavaType arrayJavaType(Class<?> clazz){
        return typeFactory().constructCollectionType(List.class,clazz);
    }

    public static JavaType arrayJavaType(JavaType javaType){
        return typeFactory().constructCollectionType(List.class,javaType);
    }

    public static JavaType mapJavaType(Class<?> keyClass,Class<?> valueClass){
        return typeFactory().constructMapType(Map.class,keyClass,valueClass);
    }

    public static JavaType mapJavaType(Class<?> valueClass){
        return mapJavaType(String.class,valueClass);
    }

    public static JavaType mapJavaType(JavaType keyType,JavaType valueType){
        return typeFactory().constructMapType(Map.class,keyType,valueType);
    }

    public static JavaType mapJavaType(JavaType valueType){
        return mapJavaType(javaType(String.class),valueType);
    }
}
